import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'
import store from '@/store'
Vue.use(VueRouter)

const routes = [
  {
    path: '/home',
    name: 'Home',
    component: Home
  },
  // {
  //   path: '/about',
  //   name: 'About',
  //   component: () => import(/* webpackChunkName: "about" */ '@/views/About.vue')
  // },
  // {
  //   path: '/cities',
  //   name: 'Cities',
  //   component: () => import(/* webpackChunkName: "cities" */ '@/views/Cities.vue'),
  //   children: [
  //     {
  //       path: 'show-city',
  //       name: 'Show-city',
  //       component: () => import(/* webpackChunkName: "show-city" */ '@/views/cities/ShowCity.vue')
  //     },
  //     {
  //       // 当 /user/:id/profile 匹配成功，
  //       // UserProfile 会被渲染在 User 的 <router-view> 中
  //       path: 'search-city',
  //       name: 'Search-city',
  //       component: () => import(/* webpackChunkName: "search-city" */ '@/views/cities/SearchCity.vue')
  //     },
  //     { path: '/cities', redirect: { name: 'Show-city' } }
  //   ]
  // },
  {
    path: '/search',
    name: 'Search',
    component: () => import(/* webpackChunkName: "search-page" */'@/views/Search.vue')
  },
  {
    path: '/classify',
    name: 'Classify',
    component: () => import(/* webpackChunkName: "classify" */ '@/views/Classify.vue')
  },
  // {
  //   path: '/classify/copy',
  //   name: 'Classify-details-copy',
  //   component: () => import('@/views/classify/Copy.vue')
  // },
  // {
  //   path: '/classify/spec',
  //   name: 'Classify-details-spec',
  //   component: () => import('@/views/classify/Spec.vue')
  // },
  {
    path: '/classify/details/:tradeItemId?',
    name: 'Classify-details-tradeItemId',
    component: () => import('@/views/classify/details/_tradeItemId.vue')
  },
  {
    path: '/paymentpage',
    name: 'Paymentpage',
    component: () => import('@/views/PaymentPage.vue')
  },
  {
    path: '/shopcart',
    name: 'Shopcart',
    component: () => import('@/views/Shoppingcart.vue')
  },
  {
    path: '/address',
    name: 'Address',
    component: () => import(/* webpackChunkName: "address" */ '@/views/address.vue'),
    children: [
      {
        path: 'list',
        name: 'Address-list',
        component: () => import(/* webpackChunkName: "address-list" */ '@/views/address/Addresslist.vue')
      },
      {
        path: 'manage',
        name: 'Address-manage',
        component: () => import(/* webpackChunkName: "address-manage" */ '@/views/address/Addressmanage.vue')
      },
      {
        path: 'edit/:editType?',
        name: 'Address-edit',
        component: () => import(/* webpackChunkName: "address-edit" */ '@/views/address/Addressedit.vue')
      },
      { path: '/address', redirect: { name: 'Address-list' } }
    ]
  },
  {
    path: '/notice',
    name: 'Notice',
    component: () => import(/* webpackChunkName: "notice-list" */ '@/views/NoticeList.vue')
  },
  {
    path: '/user/menu',
    name: 'User-menu',
    component: () => import('@/views/user/menu.vue')
  },
  {
    path: '/user/modify-pwd',
    name: 'User-modify-pwd',
    component: () => import('@/views/user/modifyPwd.vue')
  },
  {
    path: '/user/coupons',
    name: 'User-coupons',
    component: () => import('@/views/user/coupons.vue')
  },
  {
    path: '/user/result',
    name: 'User-result',
    component: () => import('@/views/user/result.vue')
  },
  {
    path: '/user/signin/:type',
    name: 'User-signin',
    component: () => import('@/views/user/signin.vue')
  },
  {
    path: '/user/order/:type?',
    name: 'User-order',
    component: () => import('@/views/user/order.vue')
  },
  {
    path: '/user',
    name: 'User',
    component: () => import(/* webpackChunkName: "user" */ '@/views/User.vue')
  },
  {
    path: '/user/:type?',
    name: 'User-type',
    component: () => import(/* webpackChunkName: "user-type" */ '@/views/user/_type.vue')
  },
  { path: '', redirect: { name: 'Home' } },
  { path: '/', redirect: { name: 'Home' } },
  { path: '*', redirect: { name: 'Home' } }
]

const router = new VueRouter({
  mode: 'hash', // history
  base: process.env.BASE_URL,
  routes
})

router.beforeEach((to, from, next) => {
  // TODO: 每次跳转的时候关闭overlay
  if (store.state.overlayModule.slider) {
    store.commit('overlayModule/CHANGESLIDER', false)
  }
  next()
})

export default router
